package com.shiguiwu.springmybatis.spring.aop.principle;

import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @description: 强制使用cg
 * @author: stone
 * @date: Created by 2021/6/9 15:29
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.aop.principle
 */
public class AopCglibTests {

    public static void main(String[] args) {
        ProxyFactory proxyFactory = new ProxyFactory();

        proxyFactory.addAdvice(new MethodBeforeAdvice() {
            @Override
            public void before(Method method, Object[] objects, Object o) throws Throwable {
                System.out.println(method.getName());
            }
        });

        proxyFactory.setTarget(new FunsService());

        Object proxy = proxyFactory.getProxy();

        //强制使用cglib代理
        proxyFactory.setProxyTargetClass(true);

        System.out.println(proxy.getClass());
        Class<?> superclass = proxy.getClass().getSuperclass();
        System.out.println(superclass.getName());

        Class<?>[] interfaces = proxy.getClass().getInterfaces();
        Arrays.stream(interfaces).forEach(System.out::println);
    }
}
